@set NET_FRAMEWORK="%WINDIR%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
@set SOLUTION_FILE="FareLiz.sln"

@del /F /S /Q *.log > nul 2>&1

@echo Restoring NuGet packages...
@%CD%\.nuget\NuGet.exe restore %SOLUTION_FILE%
@IF %ERRORLEVEL% NEQ 0 GOTO  Error
@echo.

@set PLATFORM=x64

:StartBuild
@set OUTPUT_DIR=%CD%\Bin\%PLATFORM%
@set LOG_FILE=Release.%PLATFORM%.log
@echo =========================================================
@echo PROCESSING %PLATFORM% BUILD...
@echo =========================================================
@echo Cleaning up %PLATFORM% Release...
@del /F /S /Q "%OUTPUT_DIR%\*" > nul 2>&1

@echo Building %PLATFORM% Release...
@%NET_FRAMEWORK% %SOLUTION_FILE% /t:Rebuild /p:Configuration=Release /p:Platform=%PLATFORM% > "%LOG_FILE%" 2>&1
@echo Exit code %ERRORLEVEL% >> "%LOG_FILE%"
@IF %ERRORLEVEL% NEQ 0 GOTO  Error

@IF %PLATFORM%==x64 (
	@set PLATFORM=x86
	@echo.
	GOTO StartBuild
)

@echo.
@echo Creating installers...
@"%OUTPUT_DIR%\FareLiz.Service.exe" SkyDean.FareLiz.Service.Versioning.VersionPublishService ^
							   x86 "%CD%\Bin\x86" x64 "%CD%\Bin\x64" output "%CD%\Bin" ^
							   innoExe "%CD%\packages\Tools.InnoSetup.5.5.5\tools\ISCC.exe" innoScript "%CD%\FareLizInstallerScript.iss" > "Publish.log" 2>&1
@IF %ERRORLEVEL% EQU 0 GOTO  End

:Error
@echo An error occured. Process halted!
@pause

:End